package com.whfc.ms.api.fuum.controller;

import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.fuum.entity.AppMeetingMinutes;
import com.whfc.common.result.Result;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.fuum.service.MsMeetingMinutesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目管理-会议纪要
 *
 * @author dzg
 * @since 2025-11-21
 */
@RestController
@RequestMapping("/ms/api/meeting/minutes")
public class MeetingMinutesController {

    @Autowired
    private MsMeetingMinutesService meetingMinutesService;

    /**
     * 获取会议纪要列表
     */
    @GetMapping("/list")
    public Result getMinutesList(@RequestParam("deptId") Integer deptId,
            @RequestParam(value = "name", required = false) String name) {
        List<AppMeetingMinutes> list = meetingMinutesService.list(deptId, name);
        return ResultUtil.success(list);
    }

    /**
     * 获取会议纪要详情
     */
    @GetMapping("/detail/{id}")
    public Result getMinutesDetail(@PathVariable("id") Integer id) {
        AppMeetingMinutes minutes = meetingMinutesService.getById(id);
        return ResultUtil.success(minutes);
    }

    /**
     * 新增会议纪要
     */
    @PostMapping("/add")
    public Result addMinutes(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
            @RequestBody AppMeetingMinutes minutes) {
        minutes.setCreateUser(user.getId());
        minutes.setUpdateUser(user.getId());
        return ResultUtil.success(meetingMinutesService.save(minutes));
    }

    /**
     * 更新会议纪要
     */
    @PostMapping("/update")
    public Result updateMinutes(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
            @RequestBody AppMeetingMinutes minutes) {
        minutes.setUpdateUser(user.getId());
        return ResultUtil.success(meetingMinutesService.update(minutes));
    }

    /**
     * 删除会议纪要
     */
    @PostMapping("/delete/{id}")
    public Result deleteMinutes(@PathVariable("id") Integer id) {
        boolean result = meetingMinutesService.delete(id);
        return ResultUtil.success(true);
    }

    /**
     * 批量删除会议纪要
     */
    @PostMapping("/deleteBatch")
    public Result deleteBatchMinutes(@RequestBody List<Integer> ids) {
        boolean result = meetingMinutesService.deleteBatch(ids);
        return ResultUtil.success(true);
    }
}